﻿Imports Runa.Resources.ContentManagers
Imports System.Reflection

Namespace Global.Runa.Graphics.Effects

    Public Class EffectBase

        Public Property Game() As Game

        Public Overridable Property Effect() As Effect
            Get
                Return Me._Effect
            End Get
            Set(value As Effect)
                Me._Effect = value.Clone()
            End Set
        End Property

        Protected _Opacity As Single
        Protected _Content As ResourceStreamContentManager
        Protected _ContentRoot As String
        Protected _Effect As Effect

        Public ReadOnly Property Parameters() As EffectParameterCollection
            Get
                If Me.Effect IsNot Nothing Then
                    Return Me.Effect.Parameters
                Else
                    Return Nothing
                End If
            End Get
        End Property

        Public Overridable Property Opacity() As Single
            Get
                Return Me._Opacity
            End Get
            Set(value As Single)
                If Me._Opacity <> value AndAlso value >= 0 AndAlso value <= 1 Then
                    Me._Opacity = value
                    Me.Effect.Parameters("Opacity").SetValue(Me._Opacity)
                End If
            End Set
        End Property

        Public Sub New(g As Game)
            Me.Game = g
            Me._ContentRoot = GetType(EffectBase).Assembly.FullName
            Me._Content = New ResourceStreamContentManager(g.Content.ServiceProvider, Me._ContentRoot)
        End Sub

        Public Sub New(g As Game, ByVal asm As Assembly)
            Me.Game = g
            Me._Content = New ResourceStreamContentManager(g.Content.ServiceProvider, asm.GetName().Name, asm)
        End Sub

        Public Sub New(ByVal g As Game, ByVal e As Effect)
            Me.New(g)
            Me.Effect = e
        End Sub

        Public Overridable Sub UpdataParameters(Gametime As GameTime)
            Me.Effect.Parameters("Opacity").SetValue(Me._Opacity)
        End Sub

    End Class

End Namespace